package com.foxit.pdf2html5.progressbar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;

/**
 * Upload progress listener class.
 *  
 * @author Xiangshang Yu.
 *
 */
public class FileUploadProgressListener implements ProgressListener {

	private HttpSession session;
	//private long megaBytes = -1;
	public static final String UploadStatusSessionKey = "upladeStatus";
	
	public FileUploadProgressListener(HttpServletRequest request) {
		session = request.getSession();
		FileUploadStatus newUploadStatus = new FileUploadStatus();
		session.setAttribute(UploadStatusSessionKey, newUploadStatus);
	}

	
	public void update(long pBytesRead, long pContentLength, int pItems) {
		FileUploadStatus status = (FileUploadStatus) session.getAttribute("upladeStatus");
		status.setStatus(0);
	    status.setReadedBytes(pBytesRead);
	    status.setTotalBytes(pContentLength);
	    status.setCurrentItem(pItems);
	}
	
}
